﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/SystemManagers/SystemManagers.master"
    Inherits="System.Web.Mvc.ViewPage<Diploma.Models.OrderDiplom>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Работа с приказом на диплом
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="order">
        <div id="OrderMenu">
            <ul>
                <li><a href="<%:Url.RouteUrl("Default",
                                           new
                                               {
                                                   controller = "SubOrderPractice",
                                                   action = "Room",
                                                   subOrderId = Model.SubOrderPractices.First().Id
                                               })%>">К под приказу на практику</a></li>
            </ul>
        </div>
        <div class="order_body">
            <div id="order-info" class="order-div-head">
                Информация о приказе на диплом
            </div>
            <div id="order-info-div">
            </div>
            <div id="order-status" class="order-div-head">
                Статус приказа на диплом
            </div>
            <div id="order-status-div">
            </div>
            <div id="order-consultant" class="order-div-head">
                Консультанты
            </div>
            <div id="order-consultant-div">
            </div>
            <div id="order-document" class="order-div-head">
                Excel
            </div>
            <div id="order-document-div">
            </div>
            <% if (Model.OrderStatu.Value > 0 && Model.OrderStatu.Value != 3) { %>
            <div id="order-upload" class="order-div-head">
                Загрузить файлы
            </div>
            <div id="order-upload-div">
            </div>
            <% } %>
            <div id="order-student" class="order-div-head">
                Список студентов
            </div>
            <div id="order-student-div">
            </div>
        </div>
        <div style="clear: both;">
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptsContent" runat="server">
    <script type="text/javascript">
        var orderId = '<%:Model.Id.ToString()%>';

        $(document).ready(function () {
            LoadStudentList();
            LoadInfo();
            LoadStatus();
            LoadExcelGeneration();
            LoadConsultants();
        });

        function LoadStudentList() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "StudentList"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-student-div").html(response);
                }
            });
        }

        function LoadConsultants() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "ConsultantForOrderList"})%>';
            $.ajax({
                url: path,
                type: "GET",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-consultant-div").html(response);
                }
            });
        }

        function LoadInfo() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "GetInfo"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-info-div").html(response);
                }
            });
        }

        function LoadEditInfo() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "GetEditForm"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-info-div").html(response);
                }
            });
        }

        function SaveInfo() {
            var title = $("#Title").val();
            var text = $("#Text").val();
            var bookName = $("#BookName").val();
            var dateAndOrderNumber = $("#DateAndOrderNumber").val();

            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "SaveInfo"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId, title: title, text: text, bookName: bookName, dateAndOrderNumber: dateAndOrderNumber }),
                success: function (response) {
                    if (response) {
                        LoadInfo();
                    }
                }
            });
        }

        function LoadStatus() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "GetStatus"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-status-div").html(response);
                }
            });
        }

        function ChangeStatus() {
            var statusId = $("#OrderStatus option:selected").val();
            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "SaveStatus"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId, statusId: statusId }),
                success: function (response) {
                    LoadStatus();
                    window.location.reload();
                }
            });
        }

        function LoadExcelGeneration() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "LoadExcelView"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-document-div").html(response);
                }
            });
        }
    </script>
    <% if (Model.OrderStatu.Value > 0 && Model.OrderStatu.Value != 3) {%>
    <script type="text/javascript">

        $(document).ready(function () {
            LoadUploadFiles();
        });

        function LoadUploadFiles() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "OrderDiplom", action = "UploadFilesView"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-upload-div").html(response);
                }
            });
        }
    </script>
    <%
        }%>
</asp:Content>
